Skip to content

Conversation

@seratch
Copy link
Member

@seratch seratch commented Sep 8, 2025

This pull request resolves an existing bug where the JSON format debug logging raises a Runtime exception when a given data has Iterable objects within it.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codex Review: Here are some suggestions.

Reply with @codex fix comments to fix any unresolved comments.

About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you open a pull request for review, mark a draft as ready, or comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex fix this CI failure" or "@codex address that feedback".

Comment on lines 287 to 303
if _debug.DONT_LOG_MODEL_DATA:
logger.debug("Calling LLM")
else:
messages_json = json.dumps(
_to_dump_compatible(converted_messages),
indent=2,
ensure_ascii=False,
)
tools_json = json.dumps(
_to_dump_compatible(converted_tools),
indent=2,
ensure_ascii=False,
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Avoid exhausting iterator inputs during debug logging

The new _to_dump_compatible call builds JSON strings from converted_messages and converted_tools solely for logging, but the same objects are later sent to litellm.acompletion. When those structures contain generators or other one-shot iterables—the precise case this helper targets—the conversion step consumes them, so the subsequent API call receives empty content or tool definitions. Logging needs to operate on a copy and reuse that converted structure for the request, or otherwise clone the iterables before iterating.

Useful? React with 👍 / 👎.

Comment on lines 259 to 273
if _debug.DONT_LOG_MODEL_DATA:
logger.debug("Calling LLM")
else:
messages_json = json.dumps(
_to_dump_compatible(converted_messages),
indent=2,
ensure_ascii=False,
)
tools_json = json.dumps(
_to_dump_compatible(converted_tools),
indent=2,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Prevent logging helper from draining message iterables

Here _to_dump_compatible is invoked to stringify converted_messages and converted_tools, but the original objects are still forwarded to chat.completions.create. Any generator or iterator nested inside (e.g., content lists produced lazily) will be exhausted while building the log string, leaving the API call with empty data. Consider converting the inputs once and using the converted copy both for logging and for the request so that iterables are not consumed prematurely.

Useful? React with 👍 / 👎.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seratch i think codex is correct here?

Copy link
Member Author

@seratch seratch Sep 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, yeah. This is a good catch!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@codex can you fix this comment?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

Testing

  • make format
  • make lint
  • ⚠️ make mypy (fails: missing optional dependencies numpy, litellm, sqlalchemy)
  • ⚠️ make tests (fails during collection because optional dependencies litellm and numpy are not installed)

View task →

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took over the changes ^ locally and pushed the commit

Comment on lines 259 to 273
if _debug.DONT_LOG_MODEL_DATA:
logger.debug("Calling LLM")
else:
messages_json = json.dumps(
_to_dump_compatible(converted_messages),
indent=2,
ensure_ascii=False,
)
tools_json = json.dumps(
_to_dump_compatible(converted_tools),
indent=2,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seratch i think codex is correct here?

@seratch seratch force-pushed the iterable-debug-logging branch from c61b6e1 to 3ead6ef Compare September 8, 2025 23:03
@seratch
Copy link
Member Author

seratch commented Sep 8, 2025

@rm-openai This one should be good to go now

@rm-openai rm-openai merged commit 625083a into main Sep 11, 2025
5 checks passed
@rm-openai rm-openai deleted the iterable-debug-logging branch September 11, 2025 17:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants